|
|
|
|
|
|
|
Creating a Simple Animation |
|
|
|
|
|
|
|
|
To see how easily you can use the Timer control, create a simple animation now: |
|
|
|
|
|
|
|
|
1. Start a new Standard EXE project in Visual Basic. |
|
|
|
|
|
|
|
|
2. Place a Timer control and an Image control on the form. |
|
|
|
|
|
|
|
|
3. From the Properties window on the Image control, select the ellipsis button next to the Picture property. |
|
|
|
|
|
|
|
|
4. When the Load Picture dialog box appears, select an icon file from your Visual Basic \Graphics\Icons directory. For example, select the file FACE03.ICO from the Misc directory. The Image control should now contain an image of some type. |
|
|
|
|
|
|
|
|
5. Enter the following code in the Timer event, FormLoad event, and declarations section: |
|
|
|
|
|
|
|
|
Dim xChange As Integer
Dim yChange As Integer
Private Sub Form_Load()
xChange = 100
yChange = 100
End Sub
Private Sub Timer1_Timer()
Image1.Left = Image1.Left + xChange
Image1.Top = Image1.Top + yChange
If Image1.Left > Me.ScaleWidth Then xChange = xChange * -1
If Image1.Left < 0 Then xChange = xChange * -1
If Image1.Top > Me.ScaleHeight Then yChange = yChange * -1
If Image1.Top < 0 Then yChange = yChange * -1
End Sub |
|
|
|
|
|
|
|
|
6. Open the Properties window for the Timer control. |
|
|
|
|
|
|
|
|
7. Set the Interval property to 200 and the Enabled property to True. |
|
|
|
|
|
|
|
|
When you run the program, the image should move around your form, changing direction when it ''hits" the side of the form. |
|
|
|
|
|
|
|
|
The Frame control is special because it is a type of control called a container. Containers are controls in which you can draw other controls, much like a real picture frame visually encloses (or contains) an artist's picture. When you hide a container control (using the Visible property) or change its position on a form, the controls it contains are also affected. This feature is useful for creating multiple "pages" of controls on a single form. |
|
|
|
|
|
|
|
|
|
Container controls create a different visual relationship between the form and the controls they contain. The code events and scope of variables on the form remain unaffected.  |
|
|
|
|
|
|
|
|
|
|
As with all other controls, the first step in setting up the frame control is to draw it on your form in the size that you want. Then, of course, you need to set the Name property to a unique |
|
|
|
|
|